package com.hxit.huaxiamelongarden.controller;

import com.hxit.huaxiamelongarden.domin.dto.RegisterDto;
import com.hxit.huaxiamelongarden.service.UserService;
import com.hxit.huaxiamelongarden.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName RegisterController
 * @Author 12694
 * @Date 2025/1/21 11:51
 * @Version 1.0
 **/
@RestController
@Slf4j
@RequestMapping("/register")
@CrossOrigin(origins = "*")  // 允许所有来源
public class RegisterController {
    @Autowired
    private UserService userService;
    @PostMapping()
    public Result RegisterController(@RequestBody RegisterDto registerDto) {
        log.info("用户注册{}", registerDto);
        int i = userService.insert(registerDto);
        if(i == 1){
            log.info("注册成功");
            return Result.success("注册成功");
        }
        log.info("注册失败,用户存在");
        return Result.error("该用户已存在！");
    }
}
